package main

import (
	"article_vote/config"
	"article_vote/router"
	"flag"
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"time"
)

var port int
var config_dir string

func init() {
	flag.IntVar(&port, "port", 8998, "app listen port")
	flag.StringVar(&config_dir, "config_dir", "./config.yaml", "config file")
	flag.Parse()

	config.InitConf(config_dir)

	fmt.Println("Waiting for Redis and Mysql to start...........")
	time.Sleep(time.Duration(15)*time.Second)
	config.InitMysql()
	config.InitRedis()

	//创建表
	config.CreateTable()
}

func main() {
	routers := gin.New()
	router.WebRoute(routers)
	server := &http.Server{
		Handler:           routers,
		Addr:              fmt.Sprintf("0.0.0.0:%d", 8998),
		ReadHeaderTimeout: 5 * time.Second,  //read header timeout
		ReadTimeout:       5 * time.Second,  //read request timeout
		WriteTimeout:      10 * time.Second, //write timeout
		IdleTimeout:       20 * time.Second, //tcp idle time
	}

	if err := server.ListenAndServe(); err != nil {
		fmt.Println("success.... ")
	}
}
